package com.framework.loippi.rabbitmq.sender;

import com.framework.loippi.rabbitmq.config.MQConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MQSender {

    private static Logger logger = LoggerFactory.getLogger(MQSender.class);

    @Autowired
    AmqpTemplate amqpTemplate;

    public void send(Object message) {
        logger.info("send message: " + message.toString());
        amqpTemplate.convertAndSend(MQConfig.QUEUE, message.toString());
    }

    public void sendTopic(Object message) {
        logger.info("send topic message: " + message.toString());
        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE, "topic.key1", message.toString() + "1");
        amqpTemplate.convertAndSend(MQConfig.TOPIC_EXCHANGE, "topic.key2", message.toString() + "2");
    }

    public void sendFanout(Object message) {
        logger.info("send fanout message: " + message.toString());
        amqpTemplate.convertAndSend(MQConfig.FANOUT_EXCHANGE, "", message.toString() + "1");
    }

    public void sendMiaoshMessage(Object mm) { // direct
        logger.info("miaosha send message: " +mm);
        amqpTemplate.convertAndSend(MQConfig.MIAOSHA_QUEUE, mm.toString());
    }
}
